// 导入必要的类型和函数
import { TaskHandler } from './types';
import { taskSystem } from './system';

// 参数接口
export interface Params {
  batchesCount?: number;
  currentBatch?: number;
  data?: any;
  [key: string]: any;  // 允许添加其他属性
}

// 细胞数据
export const cellData = {
  id: 'cell-001',
  type: 'stem-cell',
  status: 'frozen'
};

// 细胞相关功能函数
async function createCellTubeAnabiosis(params: Params): Promise<any> {
  console.log('创建细胞管复苏任务', params);
  return { id: 'task-' + Date.now() };
}

async function startCellTubeAnabiosis(params: Params): Promise<any> {
  console.log('开始细胞管复苏任务', params);
  return { success: true };
}

async function slotCellTubeAnabiosisFailed(error: any, params: Params): Promise<any> {
  console.error('细胞管复苏任务失败', error, params);
  return { success: false, error };
}

// 细胞管复苏任务
export const tubeRecoveryTask: TaskHandler = {
  async create(params: Params) { return createCellTubeAnabiosis(params); },
  async start(params: Params) { return startCellTubeAnabiosis(params); },
  async onFinish(result: any, params: Params) {
    const currentBatch = params.currentBatch ?? 1;
    if (currentBatch < (params.batchesCount ?? 1)) {
      return taskSystem.executeTask(tubeRecoveryTask, {
        ...params,
        currentBatch: currentBatch + 1
      });
    }
    return result;
  },
  async onFail(error: any, params: Params) { return slotCellTubeAnabiosisFailed(error, params); }
};


// 导出所有任务
export const tasks = {
  tubeRecoveryTask
};

export default tasks; 